package pure.ui 
{
	import pure.ui.core.IState;
	import pure.ui.skins.ISkin;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	
	/**
	 * 状态面板
	 * @author Des
	 * 
	 */
	
public class StatePanel extends Panel 
{
	public function StatePanel(x:Number, y:Number,size:Point,name:String,skin:ISkin=null) 
	{
		_name = name;
		super(x, y, size, skin);
	}
	
	
	
	/*model*/
	
	protected static var _panelProps:Dictionary = new Dictionary();
	
	protected var _currState:IState;
	
	protected var _name:String;
	
	/*cache*/
	
	protected var _inited:Boolean = false;

	
	
	/**
	 * 通过名称获取状态面板
	 * @param name			名称
	 **/
	public static function getStatePanelByName(name:String):StatePanel
	{
		if (_panelProps[name] != undefined)
		{
			return _panelProps[name];
		}
		return null;
	}

	
	
	
	
	
	/* ----------------------------------------------------    get / set    ----------------------------------------------------*/

	

	
	
	
	// 切换状态
	public function set state(value:IState):void
	{
		if (_currState == value)
		{
			return;
		}
		if (_currState)
		{
			_currState.exit();
		}
		_currState = value;
		update();
	}
	
	
	
	
	
	/* ----------------------------------------------------    private    ----------------------------------------------------*/
	
	
	
	
	
	override protected function _initSelf():void
	{
		super._initSelf();
		_panelProps[_name] = this;
	}
	
	/**
	 * 绘制
	 **/
	override protected function _draw():void
	{
		if (!_inited)
		{
			super._draw();
			_inited = true;
		}
		if (_currState)
		{
			_currState.enter();
		}
	}
	
}

}